// pages/openbillbox/myorderlist/myorderlist.js
import {
  proxySuppliers
} from '../../../utils/networkRequest.js'
import {
  errorMsg
} from '../../../utils/tool.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    openType: "kaidan",
    dataList: null,
    shouAddressInfo:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let self = this;
    if (options.openType) {
      this.setData({
        openType: options.openType,
        oid: options.oid ? options.oid : "",
        shouAddressInfo: options.shouAddressInfo ? options.shouAddressInfo :"",
        iscopy: options.iscopy ? options.iscopy:""
      })
    }

    proxySuppliers((r) => {
      if (r.code == 0) {
        if (options.openType == 'xiadan'){
          r.data = r.data.slice(1);
        } 
        self.setData({
          dataList: r.data
        })
      } else {
        errorMsg(r.message)
      }
    })
  },
  goAddGoods: function(e) {
    let {
      openType,
      oid,
      shouAddressInfo,
      iscopy
    } = this.data;
    let item = e.currentTarget.dataset.item;
    if (openType == "kaidan") {
      debugger;
      if (shouAddressInfo){
        wx.redirectTo({
          url: '../addgoods/addgoods?item=' + JSON.stringify(item) + "&shouAddressInfo=" + shouAddressInfo + "&iscopy=" + iscopy,
        })
      }else{
        wx.redirectTo({
          url: '../addgoods/addgoods?item=' + JSON.stringify(item),
        })
      }
     
    } else if (openType == "xiugai") {
      var pages = getCurrentPages();
      var prevPage = pages[pages.length - 2]; //上一个页面 
      //直接调用上一个页面的setData()方法，把数据存到上一个页面中去  
      prevPage.setData({
        sellerInfo: item
      })
      wx.navigateBack();
    } else if (openType == "xiadan") { 
      wx.navigateTo({
        url: "../../myorderbox/sendOrder/sendOrder?openType=tarenfahuo&oid=" + oid + "&item=" + JSON.stringify(item)
      })
    }

  },
  goHeZuoHuoBan:function(){
    wx.redirectTo({
      url: '../../invitationbox/partnerlist/partnerlist',
    })
  }
})